package goover.unit04;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.stream.Stream;

public class FileDemo01 {
    public static void main(String[] args){
        File file = new File("D:\\JAVA\\source");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        System.out.println(file.getAbsolutePath());
        System.out.println(file.exists());
        System.out.println(file.getName());
        try {
            System.out.println(file.createNewFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("路径：" + file.getPath());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getParent());
        System.out.println(file.canRead());
        System.out.println(file.canWrite());
        System.out.println(file.isFile());
        System.out.println(file.isDirectory());
        System.out.println(file.isAbsolute());
        System.out.println(file.lastModified());
        System.out.println(sdf.format(file.lastModified()));
        System.out.println(file.length());
        System.out.println("----------------------");
        if(file.isDirectory()){
            String[] filename = file.list();
            Stream.of(filename).forEach(s -> System.out.println(s));
        }
    }
}
